'use strict';
	angular.module('inventory.stocktakingGenerate', ['app.services'])

	.controller('stocktakingGenerateCtrl',['$rootScope', '$scope' , f])
    function f($rootScope, $scope) {

		var Model = this;
		
	    Model.calculate = function(){
	    	if(!$scope.documentNo){
	    		alert('盘点单号不能为空！');
	    		return;
	    	}
	    	
	    	var options = {};
	    	options.documentNo = $scope.documentNo;
	    	options.method = $scope.selected;
	    	
			$.ajax({
	            type: "POST",
	            async : true,//异步（默认），同步为false
	            url: $rootScope.getProjectName() + "/inventory/stocktaking/generate/start",
	            data: JSON.stringify(options),
	            contentType: "application/json; charset=utf-8",
	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
					console.log('data->',data);
					if(data.code==0){
						alert("操作成功");
					}else{
						alert("操作失败："+data.info);
					}
	            },
	            error: function (msg) {
	                alert('ajax调用错误信息：'+msg.responseText);
	            }
	        });
	    };


		
		return Model;
	}	
	
